#include<iostream>
using namespace std;

int diagonalSum(int matrix[][3], int n) {
    int sum = 0;
    
    for (int i = 0; i < n; i++) {
        sum += matrix[i][i]; 
        sum += matrix[i][n - 1 - i]; 
    }

    if (n % 2 == 1) {
        sum -= matrix[n / 2][n / 2];
    }

    return sum;
}

int main() {
    int matrix[][3] = {{1, 2, 3},
                       {4, 5, 6},
                       {7, 8, 9}};
    int n = 3;
    
    int result = diagonalSum(matrix, n);
    
    cout << "矩阵对角线元素的和为：" << result << endl;
    
    return 0;
}